package com.huadao.cart_ccs.experiment.log.baseLoglist;

import com.huadao.cart_ccs.common.ProjectManager;
import com.huadao.cart_ccs.data.bo.ExperimentStage;
import com.huadao.cart_ccs.experiment.log.OnDay;
import com.huadao.cart_ccs.greendao.GreenDaoManager;
import com.huadao.cart_ccs.greendao.gen.ExperimentStageDao;
import com.huadao.cart_ccs.greendao.gen.OperationDao;

import org.greenrobot.greendao.AbstractDao;

import java.util.List;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

public abstract class BaseLogListPresenter extends IBaseLogListContract.IBaseLogListPresenter{

    private ExperimentStageDao experimentStageDao;
    protected int skip;
    protected int count=50;
    protected int day=1;
    protected long projectId;
    protected long stageId=-1;
    protected Disposable getData_dispose;
    protected String condition;

    public BaseLogListPresenter(IBaseLogListContract.IBaseLogListView baseView) {
        attachView(baseView);

        projectId=ProjectManager.getInstance().getProjectId();
        experimentStageDao=GreenDaoManager.getInstance().getNoCacheSession().getExperimentStageDao();
    }

    @Override
    void setDay(int day) {
        this.day=day;
        initStageId();
    }

    @Override
    int getDay() {
        return day;
    }

    @Override
    String getCondition() {
        return condition;
    }

    @Override
    void setCondition(String condition) {
        this.condition=condition;
    }

    private void initStageId(){
        List<ExperimentStage> experimentStageList=experimentStageDao.queryBuilder().where(ExperimentStageDao.Properties.ProjectId.eq(projectId),ExperimentStageDao.Properties.Day.eq(day)).list();
        if(experimentStageList!=null&&experimentStageList.size()>0) {
            stageId=experimentStageList.get(0).getId();
        }else {
            stageId=-1;
        }
    }

    @Override
    public void detachView() {
        if(getData_dispose!=null){
            getData_dispose.dispose();
        }
        super.detachView();
    }
}
